package k4_thread.demo04;

public class ThreadFour {

    /**
     * 如果方法中没有锁修饰，不受锁的限制
     * @param args
     */
    public static void main(String[] args) {

        System.out.println("=====start=====");

        Phone4 phone = new Phone4();

        //第一个线程，表示发送短信
        new Thread(()->phone.sendMessage()).start();
        //第二个线程，表示打电话
        new Thread(()->phone.callPhone()).start();
        //第二个线程，表示发微信
        new Thread(()->phone.weChat()).start();
    }
}

class Phone4{

    public synchronized void sendMessage(){
        try {
            Thread.sleep(3000);
            System.out.println("=====发短信=====");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public synchronized void callPhone(){
        System.out.println("=====打电话=====");
    }

    public void weChat(){
        System.out.println("=====发微信=====");
    }

}
